#include<iostream>
#include<climits>
using namespace std;
const int N=2e5+10;
int nums[N];
int ret=INT_MIN;
void part(int start,int end)
{
	if(end<=start)
	{
		ret=max(ret,nums[end]);
		return;
	}
	int mid=(start+end)/2;

	part(start,mid);
	part(mid+1,end);

	int sum=nums[mid],mleft=sum;

	for(int i=mid-1;i>=start;i--)
	{
		sum+=nums[i];
		mleft=max(mleft,sum);
	}

	sum=nums[mid+1];int mright=sum;

	for(int i=mid+2;i<=end;i++)
	{
		sum+=nums[i];
		mright=max(mright,sum);
	}
	ret=max(ret,mleft+mright);

}
int main()
{
	int n;cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>nums[i];
	}
	part(1,n);
	cout<<ret<<endl;
}